home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / userbox / publicdomain / xfd / developper / sources / chryseis.s < prev    next >
Text File  |  1996-08-03  |  6KB  |  299 lines

  1. *******************************************************
  2. **   XFD external decruncher for Chryseis Cruncher   **
  3. **        written and © 1994 by Georg Hörmann        **
  4. *******************************************************
  5. **
  6. ** 28.02.96 - Updated for xfdmaster.library v37
  7. **
  8.  
  9.         OUTPUT    "LIBS:xfd/Chryseis"
  10.  
  11.         SECTION    Chryseis,CODE
  12.  
  13.         INCDIR    "dh0:Include_Asm"    ;change this as you need it
  14.         INCLUDE    "dh0:xfd/xfdmaster.i"
  15.  
  16. ; xfdForeman structure MUST be first thing in all external decrunchers
  17.  
  18. F_Chryseis    moveq    #-1,d0        ;security
  19.         rts
  20.         dc.l    XFDF_ID        ;id
  21.         dc.w    1        ;version
  22.         dc.w    0
  23.         dc.l    0,0        ;private
  24.         dc.l    S_Chryseis09    ;first slave
  25.  
  26.         dc.b    "$VER: XFD Chryseis decruncher by Georg Hörmann",13,10,0
  27.         cnop    0,4
  28.  
  29. **************************************************
  30.  
  31. ; xfdSlave structure: this one doesn't support segment decrunching
  32.  
  33. S_Chryseis09    dc.l    0        ;no more slaves
  34.         dc.w    2        ;version
  35.         dc.w    36        ;master version
  36.         dc.l    N_Chryseis09    ;name
  37.         dc.w    XFDPFF_RELOC    ;flags
  38.         dc.w    0
  39.         dc.l    RB_Chryseis09    ;recog buffer
  40.         dc.l    DB_Chryseis09    ;decrunch buffer
  41.         dc.l    0        ;recog segment
  42.         dc.l    0        ;decrunch segment
  43.         dc.w    0,0        ;slave/replace id
  44.         dc.l    $4bc+32        ;min. file length for header and data
  45.  
  46. N_Chryseis09    dc.b    'Chryseis Cruncher 0.9',0
  47.         even
  48.  
  49. ;-------------------------------------------------
  50.  
  51. ; Recog buffer function: receives buffer + length in a0/d0
  52.  
  53. RB_Chryseis09    ;cmp.l    #$4bc+32,d0  --> obsolete (see slave v2)
  54.         ;ble.s    .Exit
  55.         cmp.w    #$abcd,$2a(a0)    ;some more verification
  56.         bne.s    .Exit
  57.         cmp.w    #$03f6,$4ba(a0)
  58.         bne.s    .Exit
  59.  
  60.         cmp.l    #$208f205f,$42(a0)
  61.         bne.s    .Exit
  62.         cmp.l    #$4eba01c8,$46(a0)
  63.         bne.s    .Exit
  64.         cmp.l    #$49fa025c,$214(a0)
  65.         bne.s    .Exit
  66.         moveq    #1,d0
  67.         rts
  68.  
  69. .Exit        moveq    #0,d0
  70.         rts
  71.  
  72. ;-------------------------------------------------
  73.  
  74. ;Decrunch buffer function: receives bufferinfo in a0
  75.  
  76. DB_Chryseis09    movem.l    d2-d7/a2-a6,-(a7)
  77.         move.l    a0,a5
  78.         move.l    xfdbi_SourceBuffer(a5),a2
  79.  
  80. ; first of all, we calculate the length of the decrunched file
  81.  
  82.         moveq    #20,d2        ;3f3,0,x,0,x-1
  83.         lea    $4bc(a2),a0
  84.         move.l    (a0),d0
  85.         move.l    d0,d3        ;amount hunks
  86.         lsl.l    #2,d0
  87.         add.l    d0,d2        ;hunklens
  88.         lea    12(a0,d0.l),a0
  89.         
  90. .CountAgain    addq.l    #8,d2        ;3ex,x
  91.         move.w    (a0)+,d0
  92.         move.w    (a0)+,d1
  93.         cmp.w    #$3eb,d1
  94.         bne.s    .CountNoBSS
  95.         addq.w    #4,a0
  96.         bra.s    .CountReloc
  97.  
  98. .CountNoBSS    and.w    #$0fff,d0
  99.         beq.s    .CountUncr
  100.  
  101.         move.l    (a0),d0
  102.         add.l    d0,a0
  103.         move.l    (a0)+,d0
  104.         lsr.l    #8,d0
  105.         add.l    d0,d2        ;uncr hunklen
  106.         bra.s    .CountReloc
  107.  
  108. .CountUncr    move.l    (a0)+,d0
  109.         add.l    d0,d2
  110.         add.l    d0,a0
  111.  
  112. .CountReloc    addq.l    #4,d2        ;end|reloc
  113.         cmp.l    #$3f2,(a0)+
  114.         beq.s    .CountEnd
  115.  
  116. .CountNextRel    addq.l    #4,d2
  117.         move.l    (a0)+,d0
  118.         beq.s    .CountReloc
  119.         addq.l    #1,d0
  120.         lsl.l    #2,d0
  121.         add.l    d0,d2
  122.         add.l    d0,a0
  123.         bra.s    .CountNextRel
  124.  
  125. .CountEnd    subq.l    #1,d3
  126.         bne.s    .CountAgain
  127.  
  128. ; now we have the desired length and allocate the buffer
  129.  
  130.         move.l    d2,d0
  131.         move.l    d0,xfdbi_TargetBufSaveLen(a5)
  132.         move.l    d0,xfdbi_TargetBufLen(a5)
  133.  
  134.         move.l    xfdbi_TargetBufMemType(a5),d1
  135.         move.l    4.w,a6
  136.         jsr    -198(a6)
  137.         move.w    #XFDERR_NOMEMORY,xfdbi_Error(a5)
  138.         move.l    d0,xfdbi_TargetBuffer(a5)
  139.         beq    .Exit
  140.  
  141. ; let's fill the buffer
  142.  
  143.         move.l    d0,a3
  144.         move.l    #$3f3,(a3)+
  145.         clr.l    (a3)+
  146.         lea    $4bc(a2),a2
  147.         move.l    (a2),d0
  148.         move.l    d0,d3
  149.         addq.w    #3-1,d0
  150. .CopyHeader    move.l    (a2)+,(a3)+
  151.         dbf    d0,.CopyHeader
  152.  
  153. .CopyAgain    move.w    (a2)+,d0
  154.         move.w    (a2)+,d1
  155.         clr.w    (a3)+
  156.         move.w    d1,(a3)+
  157.         cmp.w    #$3eb,d1
  158.         bne.s    .NoBSS
  159.         move.l    (a2)+,d0
  160.         lsr.l    #2,d0
  161.         move.l    d0,(a3)+
  162.         bra.s    .CopyReloc
  163.  
  164. .NoBSS        and.w    #$0fff,d0
  165.         beq.s    .CopyUncr
  166.         move.l    (a2),d1
  167.         add.l    d1,a2
  168.         move.l    (a2)+,d1
  169.         lsr.l    #8,d1
  170.         lsr.l    #2,d1
  171.         move.l    d1,(a3)+
  172.         move.l    a2,a0
  173.         move.l    a3,a1
  174.         lsl.l    #2,d1
  175.         add.l    d1,a3
  176.         lsl.w    #2,d0
  177.         move.l    a2,-(a7)
  178.         lea    .EffTable-4(pc),a2
  179.         add.w    d0,a2
  180.         bsr    D_Chryseis
  181.         move.l    (a7)+,a2
  182.         bra.s    .CopyReloc
  183.  
  184. .CopyUncr    move.l    (a2)+,d0
  185.         lsr.l    #2,d0
  186.         move.l    d0,(a3)+
  187. .CopyUncr1    move.l    (a2)+,(a3)+
  188.         subq.l    #1,d0
  189.         bne.s    .CopyUncr1
  190.  
  191. .CopyReloc    move.l    (a2)+,d0
  192.         move.l    d0,(a3)+
  193.         cmp.w    #$3f2,d0
  194.         beq.s    .CopyEnd
  195.  
  196. .CopyNextRel    move.l    (a2)+,d0
  197.         move.l    d0,(a3)+
  198.         beq.s    .CopyReloc
  199.         addq.l    #1,d0
  200. .CopyEntries    move.l    (a2)+,(a3)+
  201.         subq.l    #1,d0
  202.         bne.s    .CopyEntries
  203.         bra.s    .CopyNextRel
  204.  
  205. .CopyEnd    subq.l    #1,d3
  206.         bne.s    .CopyAgain
  207.  
  208. ; successful exit
  209.  
  210.         moveq    #1,d0
  211. .Exit        movem.l    (a7)+,d2-d7/a2-a6
  212.         rts
  213.  
  214. .EffTable    dc.b    9,9,9,9
  215.         dc.b    9,10,10,10
  216.         dc.b    9,10,11,11
  217.         dc.b    9,10,12,12
  218.         dc.b    9,10,12,13
  219.  
  220. **************************************************
  221.  
  222. D_Chryseis    movem.l    d2-d5/a2/a3,-(a7)
  223.         moveq    #-1,d4
  224.         moveq    #1,d5
  225.         move.l    a1,a3
  226.         move.l    -(a0),d1
  227.         tst.b    d1
  228.         beq.s    .Decr1
  229.         bsr.s    .Decr5
  230.         subq.b    #1,d1
  231.         lsr.l    d1,d5
  232. .Decr1        lsr.l    #8,d1
  233.         add.l    d1,a1
  234. .Decr2        bsr.s    .Decr5
  235.         bcs.s    .Decr11
  236.         moveq    #0,d2
  237. .Decr3        moveq    #1,d0
  238.         bsr.s    .Decr8
  239.         add.w    d1,d2
  240.         subq.w    #3,d1
  241.         beq.s    .Decr3
  242. .Decr4        moveq    #7,d0
  243.         bsr.s    .Decr8
  244.         move.b    d1,-(a1)
  245.         cmp.l    a3,a1        ; modified for
  246.         dbeq    d2,.Decr4    ; perfect error
  247.         cmp.w    d4,d2        ; detection
  248.         beq.s    .Decr11
  249.         bra.s    .Decr17
  250.  
  251. .Decr5        lsr.l    #1,d5
  252.         beq.s    .Decr6
  253.         rts
  254. .Decr6        move.l    -(a0),d5
  255.         roxr.l    #1,d5
  256.         rts
  257.  
  258. .Decr7        subq.w    #1,d0
  259. .Decr8        moveq    #0,d1
  260. .Decr9        lsr.l    #1,d5
  261.         bne.s    .Decr10
  262.         move.l    -(a0),d5
  263.         roxr.l    #1,d5
  264. .Decr10        roxl.l    #1,d1
  265.         dbra    d0,.Decr9
  266.         rts
  267.  
  268. .Decr11        moveq    #1,d0
  269.         bsr.s    .Decr8
  270.         moveq    #0,d0
  271.         move.b    (a2,d1.w),d0
  272.         move.w    d1,d2
  273.         subq.w    #3,d1
  274.         bne.s    .Decr14
  275.         bsr.s    .Decr5
  276.         bcs.s    .Decr12
  277.         moveq    #7,d0
  278. .Decr12        bsr.s    .Decr7
  279.         move.w    d1,d3
  280. .Decr13        moveq    #2,d0
  281.         bsr.s    .Decr8
  282.         add.w    d1,d2
  283.         subq.w    #7,d1
  284.         beq.s    .Decr13
  285.         bra.s    .Decr15
  286.  
  287. .Decr14        bsr.s    .Decr7
  288.         move.w    d1,d3
  289. .Decr15        addq.w    #1,d2
  290. .Decr16        move.b    (a1,d3.w),-(a1)
  291.         cmp.l    a3,a1        ; modified
  292.         dbeq    d2,.Decr16    ; for perfect
  293.         cmp.w    d4,d2        ; error detection
  294.         beq.s    .Decr2
  295. .Decr17        movem.l    (a7)+,d2-d5/a2/a3
  296.         rts
  297.  
  298.         END
  299.